package com.kgc.provider;


import com.kgc.constant.ActiveMqConstant;
import com.kgc.util.ReturnResult;
import lombok.extern.slf4j.Slf4j;


import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;


import javax.jms.Destination;
import java.util.Map;

@Slf4j
@Component
public class CarActiveMqQueueProvider {
    @Autowired(required = false)
    private JmsMessagingTemplate jmsMessagingTemplate;

    public  void sendMessageToQueue(String queueName,String message){
        log.info("-----------向队列中发送一条消息{}，而队列名称：{}，begin--------",message,queueName);
        //创建一个目标消息队列（容器）
//        Destination destination=new ActiveMQQueue(queueName);
        Destination destination = new ActiveMQQueue(queueName);
        jmsMessagingTemplate.convertAndSend(destination,message);
    }
    @JmsListener(destination = ActiveMqConstant.QUEUE_NAME_PRSP_TEST)
    public void receiveMessageFromConsumerResp(ReturnResult<Map<String, String>> respMsg){
        log.info("=====从加入购物车响应消息队列中，获取响应结果:{}=====",respMsg.toString());
        log.info("=====从加入购物车响应消息队列中，获取响应结果:{}=====",respMsg.getMsg());
    }
    @JmsListener(destination = "generateOrdersRESP")
    public void generateOrdersRESP(ReturnResult<Map<String, String>> respMsg){
        log.info("=====从生成订单响应消息队列中，获取响应结果:{}=====",respMsg.toString());
        log.info("=====从生成订单响应消息队列中，获取响应结果:{}=====",respMsg.getMsg());
    }

}
